package com.hghivln.controller.erp;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.controller.BaseController;
import com.hghivln.pojo.dto.ProducterDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.ProducterService;
import com.hghivln.utils.ShiroUtils;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("erp/producter")
public class ProducterController extends BaseController {

    @Reference
    private ProducterService producterService;


    /**
     * 分页查询
     */
    @HystrixCommand
    @GetMapping("listProducterForPage")
    public AjaxResult listProducterForPage(ProducterDto producterDto) {
        return producterService.listProducterForPage(producterDto);
    }


    /**
     * 添加
     */
    @HystrixCommand
    @PostMapping("addProducter")
    @Log(title = "添加生产厂家",businessType = BusinessType.INSERT)
    public AjaxResult addProducter(@Validated ProducterDto producterDto) {
        producterDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return producterService.addProducter(producterDto);
    }

    /**
     * 修改
     */
    @HystrixCommand
    @PutMapping("updateProducter")
    @Log(title = "修改生产厂家",businessType = BusinessType.UPDATE)
    public AjaxResult updateProducter(@Validated ProducterDto producterDto) {
        producterDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return producterService.updateProducter(producterDto);
    }

    /**
     * 删除
     */
    @HystrixCommand
    @DeleteMapping("deleteProducterByIds/{ids}")
    @Log(title = "删除生产厂家",businessType = BusinessType.DELETE)
    public AjaxResult deleteProducterByIds(@PathVariable @Validated @NotEmpty(message = "要删除的生产厂家ID不能为空")Long[] ids) {
        return producterService.deleteProducterByIds(ids);
    }

    /**
     * 根据ID查询一个生产厂家信息
     */
    @HystrixCommand
    @GetMapping("getProducterById/{id}")
    public AjaxResult getProducterById(@PathVariable @Validated @NotEmpty(message = "生产厂家ID不能为空") Long id) {
        return producterService.selectProducterById(id);
    }

    /**
     * 查询所有有效的生产厂家信息
     */
    @HystrixCommand
    @GetMapping("selectAllProducter")
    public AjaxResult selectAllProducter() {
        return this.producterService.selectAllProducter();
    }
}
